package cqrtplm.controller;

import com.alibaba.fastjson.JSONArray;
import com.alibaba.fastjson.JSONObject;
import com.ty.basic.constant.ApiPathConstant;
import com.ty.basic.response.ResponseResult;
import cqrtplm.service.OaApiService;
import cqrtplm.service.SapIntegrityService;
import cqrtplm.service.SrmIntegrityService;
import io.swagger.annotations.Api;
import io.swagger.annotations.ApiOperation;
import org.springframework.web.bind.annotation.PostMapping;
import org.springframework.web.bind.annotation.RequestBody;
import org.springframework.web.bind.annotation.RequestMapping;
import org.springframework.web.bind.annotation.RestController;

import javax.annotation.Resource;
import java.util.List;

@RestController
@RequestMapping(ApiPathConstant.PRODUCT_VERSION_ONE_PATH + "integrity/")
@Api(tags = "润通集成")
public class RTIntegrityController {
    @Resource
    private SrmIntegrityService srmIntegrityService;
    @Resource
    private SapIntegrityService sapIntegrityService;
    @Resource
    private OaApiService oaApiService;

    @RequestMapping("updateDrawingDownloadStatus")
    @ApiOperation(value = "SRM集成-接收SRM图纸下载情况", produces = "application/json; charset=utf-8")
    public ResponseResult updateDrawingDownloadStatus(@RequestBody JSONObject json) {
        JSONArray numberList = json.getJSONArray("partNumberList");
        List<String> list = numberList.toJavaList(String.class);
        srmIntegrityService.updateDrawingDownloadStatus(list);
        return ResponseResult.success();
    }

    @RequestMapping("queryParentPartInfo")
    @ApiOperation(value = "SRM集成-查询父部件信息", produces = "application/json; charset=utf-8")
    public ResponseResult queryParentPartInfo(@RequestBody JSONObject json) {
        JSONArray numberList = json.getJSONArray("partNumberList");
        List<String> list = numberList.toJavaList(String.class);
        return ResponseResult.success(srmIntegrityService.queryParentPartInfo(list));
    }

    @PostMapping("/getSapProjectCode")
    @ApiOperation(value = "SAP集成-获取sap中的项目令号", produces = "application/json; charset=utf-8")
    public ResponseResult getSapProjectCode(@RequestBody JSONObject params) {
        JSONArray data = sapIntegrityService.getSapProjectCode(params);
        return ResponseResult.success(data);
    }

    @PostMapping("/writeBackOAFormData")
    @ApiOperation(value = "OA集成-回写零星采购表单数据", produces = "application/json; charset=utf-8")
    public ResponseResult writeBackOAFormData(@RequestBody JSONObject params) {
        JSONObject data = oaApiService.writeBackOAFormData(params);
        return ResponseResult.success(data);
    }


}
